package log

import (
	"CodeCover/internal/config"
	"os"

	"github.com/sirupsen/logrus"
	"gopkg.in/natefinch/lumberjack.v2"
)

var Logger *logrus.Logger

func InitLogger(cfg *config.AllConfig) {

	Logger = logrus.New()

	Logger.SetFormatter(&logrus.TextFormatter{
		FullTimestamp:   true,                  // 显示完整时间戳
		TimestampFormat: "2006-01-02 15:04:05", // 时间格式
	})
	Logger.SetReportCaller(true)

	if cfg.Mode == "prod" {
		Logger.SetOutput(&lumberjack.Logger{
			Filename:   cfg.LogConfig.FilePath,
			MaxSize:    10,
			MaxBackups: 5,
			MaxAge:     30,
			Compress:   true,
		})
	} else {
		Logger.SetOutput(os.Stdout)
	}

}
